<template>
	<view>
		<uni-nav-bar statusBar="true" fixed="true" background-color="#1B18F7" color="#fff">
			<view>个人中心</view>
		</uni-nav-bar>
		<view class="user-head">
			<view class="user-head-part1">
				<view class="user-part1-login">
					<view class="user-toux">
						<image src="/static/img/gsLogo.jpg"></image>
						<view v-if="islogin"></view>
					</view>
					<view class="user-Login">
						<view class="Login-btn" v-if="islogin">
							<text>{{username}}</text>
							<text class="rightText" v-if="islogin && permission > 1">{{daoqiTime}}</text>
						</view>
						<view class="Login-btn" @tap="doLogin" v-else>点击登录</view>
						<!-- v-if="!baseConfig.isIOSshenhe && isshow" -->
						<view class="user-qx" v-if="!baseConfig.isIOSshenhe && isshow">
							<view style="display: flex;align-items: center; flex:1;">
								<text :class="permission > 1?'user-level  user-level-vip':'user-level'"
									v-if="islogin"></text>
								{{!islogin?'升级会员享受更多特权':permissionStr}}
							</view>
							<view class="rightText diquTag" v-if="islogin && permission > 1">{{user_diqu}}</view>
						</view>
					</view>
					<!-- <view class="user-sign">
						<image src="/static/img/user_03.jpg" class="sign-rili"></image> <text>签到领好礼 ></text>
					</view> -->
				</view>
			</view>
			<view class="user-head-part2">
				<view class="user-infor-num">
					<view class="infor-num-list" @click="goToPage(true,'nav', '/pages/user/guanzhu/guanzhu')">
						<!-- v-model="guanzhu" -->
						<text class="infor-num-text1">{{guanzhu}}</text>
						<view class="infor-num-text2">已关注（条）</view>
						<text class="line-h"></text>
					</view>
					<view class="infor-num-list" @click="goToPage(true,'nav', '/pages/user/shoucang/shoucangList')">
						<!--  v-model="shoucang" -->
						<text class="infor-num-text1">{{shoucang}}</text>
						<view class="infor-num-text2">已收藏（条）</view>
						<text class="line-h"></text>
					</view>
					<view class="infor-num-list" @click="goToPage(true,'nav', '/pages/user/liulan/liulanList')">
						<!-- v-model="liulan" -->
						<text class="infor-num-text1">{{liulan}}</text>
						<view class="infor-num-text2">已浏览（条）</view>
					</view>
				</view>
			</view>
		</view>
		<scroll-view :scroll-y="true" style="height: 1000rpx; padding-bottom: 120rpx;">
			<view class="user-adv" v-if="swiperImg.length>0 && !baseConfig.isIOSshenhe && isshow">
				<image :src="swiperImg[0].src" @click="goToPage(true, swiperImg[0].type, swiperImg[0].url)"></image>
			</view>
			<uni-list>
				<!--  v-if="!baseConfig.isIOSshenhe && isshow" -->
				<!-- <uni-list-item title="我的发票" thumb="/static/img/usericon1.png"
					@clickFn="goToPage(true,'nav', '/pages/user/wodefapiao/fapiaoguanli')" /> -->
				<uni-list-item title="我的会员" thumb="/static/img/usericon1.png" v-if="!baseConfig.isIOSshenhe && isshow"
					@clickFn="goToPage(true,'nav', '/pages/user/huiyuan/payment')" />
				<uni-list-item title="我的名片" thumb="/static/img/usericon2.png"
					@clickFn="goToPage(true,'nav', '/pages/user/mycard/mycard')" />
				<!-- <uni-list-item title="我的订阅" thumb="/static/img/usericon3.png"
					@clickFn="goToPage(true,'tab', '/pages/user/custom/custom')" /> -->
				<uni-list-item title="我的服务" thumb="/static/img/usericon4.png"
					@clickFn="goToPage(true,'nav', '/pages/index/function/function')" />
				<uni-list-item v-if="!baseConfig.isIOSshenhe && isshow" title="购买记录" thumb="/static/img/usericon5.png"
					@clickFn="goToPage(true,'nav', '/pages/user/goumaijilu/goumaijilu')" />
				<uni-list-item title="我的客服" thumb="/static/img/usericon6.png"
					@clickFn="goToPage(false,'nav', '/pages/user/service/service')" />
				<uni-list-item v-if="!baseConfig.isIOSshenhe && isshow" title="我的发票" thumb="/static/img/usericon1.png"
					@clickFn="goToPage(true,'nav', '/pages/user/wodefapiao/fapiaoguanli')" />
				<!-- <uni-list-item v-if="!baseConfig.isIOSshenhe && isshow" title="发票管理" thumb="/static/img/usericon10.png"
					@clickFn="goToPage(true,'nav', '/pages/user/fapiaoguanli/fapiaoguanli')" /> -->
			</uni-list>
			<uni-list>
				<uni-list-item title="设置" thumb="/static/img/usericon7.png"
					@clickFn="goToPage(false,'nav', '/pages/user/Setup/Setup')" />
				<uni-list-item title="意见反馈" thumb="/static/img/yjfk.png"
					@clickFn="goToPage(false,'nav', '/pages/user/feedback/feedback')" />
				<uni-list-item title="清空缓存" thumb="/static/img/usericon8.png" @clickFn="clearCache" v-if="islogin" />
			</uni-list>
		</scroll-view>
		<z-navigation></z-navigation>
	</view>
</template>

<script>
	/**
	 * 会员级别显示顺序：
	 * PC标准会员>移动高级会员>移动标准>免费会员
	 */
	import zNavigation from '@/components/navigation/navigation.vue';
	// import Vue from 'vue'
	// import uniList from '@/components/uni-list/uni-list.vue'
	// import uniListItem from '@/components/uni-list-item/uni-list-item.vue'
	import uLink from "@/components/uLink.vue"
	import uniIcons from '@/components/uni-icons/uni-icons.vue'
	import uniNavBar from '@/components/uni-nav-bar/uni-nav-bar.vue'
	export default {
		components: {
			// uniList,
			// uniListItem,
			uniIcons,
			uniNavBar,
			uLink,
			zNavigation
		},
		data() {
			return {
				guanzhu: 0,
				dingyue: 0,
				liulan: 0,
				shoucang: 0,
				username: '',
				user_diqu: '',
				daoqi_time: '',
				userid: 0,
				islogin: false,
				permission: 1,
				permissionStr: '免费会员',
				swiperImg: [{
					src: '/static/img/adver.jpg',
					title: '',
					url: '/pages/user/huiyuan/payment',
					type: 'nav'
				}],
				isios: false,
				isshow: true
			}
		},
		computed: {
			daoqiTime(a, b) {
				return uni.$u.timeFormat(this.daoqi_time, 'yyyy/mm/dd');
			}
		},
		onLoad() {
			// this.baseConfig.isIOSshenhe=true;
			
			this.checkLogin();
			this.username = this.currUser.user_name;
			this.islogin = this.currUser.islogin;
			//this.permission = this.currUser.user_permission;
			this.userid = this.currUser.user_id;
			if (uni.getSystemInfoSync().platform == 'ios') {
				this.isios = true;
			}
			// console.log(5,this.userid,this.baseConfig.testid)
			// if (this.isios && (this.userid == this.baseConfig.testid || !this.islogin)) {
			// 	this.isshow = false;
			// 	this.swiperImg = [];
			// }
			if (this.islogin) {
				this.binddata();
			} else {
				this.guanzhu = 0;
				this.dingyue = 0;
				this.liulan = 0;
				this.shoucang = 0;
			};
			// 隐藏原生的tabbar
			uni.hideTabBar();
		},
		onShow() {
			this.checkLogin();
			this.username = this.currUser.user_name;
			this.islogin = this.currUser.islogin;
			this.userid = this.currUser.user_id;
			if (uni.getSystemInfoSync().platform == 'ios') {
				this.isios = true;
			}
			// if (this.isios && (this.userid == this.baseConfig.testid || !this.islogin)) {
			// 	this.isshow = false;
			// 	this.swiperImg = [];
			// }

			//this.permission = this.currUser.user_permission;
			if (this.islogin) {
				this.binddata();
			} else {
				this.guanzhu = 0;
				this.dingyue = 0;
				this.liulan = 0;
				this.shoucang = 0;
			};
			// 隐藏原生的tabbar
			uni.hideTabBar();
		},

		methods: {
			gotourl(type, url) {
				//type: tab  nav
				// console.log(type + url)
				if (type == 'tab') {
					uni.switchTab({
						url: url
					})
				} else if (type == 'nav') {
					uni.navigateTo({
						url: url
					})
				}
			},
			goToPage(checklogin, type, url) {
				if (checklogin) {
					this.checkLogin();
					if (this.currUser.islogin) {
						this.gotourl(type, url)
					} else {
						url = encodeURIComponent(url);
						uni.navigateTo({
							url: '/pages/user/login/login1?type=' + type + '&fromurl=' + encodeURIComponent(url)
						})
					}
				} else {
					this.gotourl(type, url)
				}
			},
			typeidtostr(type) {
				var str = '--';
				if (type != '') {
					switch (type) {
						case 1:
							str = '免费会员'
							break;
						case 2:
							str = "标准会员";
							break;
						case 3:
							str = "高级会员";
							break;
						case 4:
							str = "vip会员";
							break;
						case 6:
							str = "金牌会员";
							break;
						case 7:
							str = "银牌会员";
							break;
						case 9:
							str = "投标通会员";
							break;
						case 27:
							str = "定制会员";
							break;

						default:
							str = '未知'
							break;
					}
					return str;
				}
			},
			binddata() {
				//异步请求数据
				let data = this.initNewData();
				// console.log(22,data)
				data.from = 4038;
				data.location = 5138;
				uni.request({
					url: this.baseConfig.serverURL + 'user/indexBindHandler.ashx', //检查更新的服务器地址
					data: data,
					method: "POST",
					header: {
						"content-type": "application/x-www-form-urlencoded" //"application/json"
					},
					success: (res) => {
						// 注：接口中isshow 为false，只有内网测试帐号 bidcenterxm（ios 审核帐号） 下始终是false，其它都是true
						if (res.statusCode == 200) {
							// console.log(55,res)
							if (!res.data.ret) {
								uni.showToast({
									title: res.data.msg,
									icon: "none"
								});
								return;
							} else {
								//获取成功，绑定
								let list = res.data.other2;
								if (list == undefined || list == null) {
									uni.showToast({
										title: "数据加载失败",
										icon: "none"
									});
									return;
								}
								this.guanzhu = list.guanzhu;
								this.dingyue = list.dingyue;
								this.liulan = list.liulan;
								this.shoucang = list.shoucang;
								this.comname = list.comname;
								this.permission = list.jibie;
								this.permissionStr = list.jibieStr;
								let list_gg = list.list_gg;
								this.swiperImg = list_gg;
								this.isshow = list.isshow;

								this.user_diqu = list.user_diqu;
								this.daoqi_time = list.daoqi_time;
								// this.isshow=false;
							}
						} else {
							uni.showToast({
								title: '绑定信息失败',
								icon: "none"
							});
						}
					},
					fail: (res) => {
						uni.showToast({
							title: '获取失败，可能已超时！',
							icon: "none"
						});
					}
				})
			},
			clearCache() {
				if (this.islogin) {
					let data = this.initNewData();
					data.from = 4038;
					data.location = 8092;
					uni.request({
						url: this.baseConfig.serverURL + '/User/setting/DelCacheHandler.ashx', //检查更新的服务器地址
						data: data,
						method: "POST",
						header: {
							"content-type": "application/x-www-form-urlencoded" //"application/json"
						},
						success: (res) => {
							if (res.statusCode == 200) {
								if (!res.data.ret) {
									uni.showToast({
										title: res.data.msg,
										icon: "none"
									});
									return;
								} else {
									//获取成功，绑定
									uni.showToast({
										title: "清除缓存成功",
										icon: "none"
									});
									return;
								}
							} else {
								uni.showToast({
									title: '清除缓存失败！',
									icon: "none"
								});
							}
						},
						fail: (res) => {
							uni.showToast({
								title: '清除缓存失败！',
								icon: "none"
							});
						}
					})
				}
			}
		}
	}
</script>
<style lang="scss" scoped>
	.rightText {
		font-size: 24rpx;
		color: #333;
		font-weight: normal;

		.diquTag {
			width: 320rpx;
			text-align: right;
			overflow: hidden;
			text-overflow: ellipsis;
			white-space: nowrap;
			flex: none;
		}
	}

	.Login-btn,
	.user-qx {
		display: flex;
		justify-content: space-between;
		align-items: center;
		margin-right: 20rpx;
	}
</style>
<style lang="scss">
	page {
		background-color: #f6f5fa;
	}

	.user-head {
		.user-head-part1 {
			background-color: #1B18F7;

			.user-part1-login {
				margin: 0 30rpx;
				background-color: #fff;
				border-radius: 20rpx;
				border-bottom-left-radius: 0;
				border-bottom-right-radius: 0;
				display: flex;
				flex-direction: row;
				align-items: center;
				padding: 20rpx 0 30rpx;

				.user-toux {
					width: 120rpx;
					height: 120rpx;
					border-radius: 100%;
					margin: 0 20rpx;
					position: relative;

					image {
						width: 100%;
						height: 100%;
					}


				}

				.user-Login {
					flex: 1 1 0%;
					font-size: 32rpx;
					line-height: 2;

					.Login-btn {
						font-weight: 700;
					}

					.user-qx {
						font-size: 28rpx;
						overflow: hidden;
						text-overflow: ellipsis;
						white-space: nowrap;
						display: flex;
						align-items: center;

						.user-level {
							background-image: url(../../static/img/huiyuan/hybs1_03.jpg);
							background-repeat: no-repeat;
							background-position: 0 0;
							background-size: 100% 100%;
							width: 50rpx;
							height: 35rpx;
							display: flex;
							margin-right: 10rpx;
						}

						.user-level-vip {
							background-image: url(/static/img/huiyuan/hybs2_03.jpg);
						}
					}
				}

				.user-sign {
					font-size: 22rpx;
					display: flex;
					align-items: center;
					background-color: #f8734c;
					height: 80rpx;
					border-top-left-radius: 90rpx;
					border-bottom-left-radius: 90rpx;
					padding: 0 20rpx;
					color: #fff;
					flex-direction: row;

					.sign-rili {
						width: 45rpx;
						height: 45rpx;
						margin-right: 10rpx;
					}
				}
			}
		}

		.user-head-part2 {

			padding: 0 30rpx;

			.user-infor-num {
				background-color: #fff;
				border-bottom-left-radius: 20rpx;
				border-bottom-right-radius: 20rpx;
				display: flex;
				flex-direction: row;
				position: relative;
				padding-bottom: 40rpx;

				.infor-num-list {
					display: flex;
					flex: 1 1 0%;
					font-weight: 700;
					justify-content: center;
					align-items: center;
					flex-direction: column;
					position: relative;

					.infor-num-text1 {
						font-size: 40rpx;
						margin-bottom: 10rpx;
					}

					.infor-num-text2 {
						font-size: 24rpx;
						color: #666666;
						display: flex;
						align-items: center;
						margin-left: 20rpx;
					}

					.line-h {
						width: 1rpx;
						background-color: #797979;
						display: block;
						height: 50rpx;
						position: absolute;
						right: 0;
						bottom: -10rpx;
					}
				}

			}
		}
	}

	.user-adv {
		margin: 20rpx 30rpx;
		height: 80rpx;

		image {
			width: 100%;
			height: 100%;
		}
	}

	/* #ifdef MP-TOUTIAO */
	@font-face {
		font-family: uniicons;
		font-weight: normal;
		font-style: normal;
		src: url('~@/static/uni.ttf') format('truetype');
	}

	/* #endif */
	.uni-list {
		margin-bottom: 20rpx;
	}
</style>